package com.example.electronicmall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.electronicmall.R;
import com.example.electronicmall.bean.ChoicepositionBean;

import java.util.List;

/*作者：王辉
* 功能：我的收货地址适配器
* 时间：2022/11/8
* */
public class ChoicepositionAapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
private List<ChoicepositionBean> list;
    private OnClickExperintListener listener;

    public ChoicepositionAapter(Context context,List<ChoicepositionBean> list) {
        this.context = context;
        this.list=list;
    }
    public void setListener(OnClickExperintListener listener) {
        this.listener = listener;
    }
    public void setList(List<ChoicepositionBean> list) {
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        return new ChoicepositionHolder(LayoutInflater.from(context).inflate(R.layout.choiceposition_item_listview,null));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ((ChoicepositionHolder)holder).choicename.setText(list.get(position).getChoicepositionName());
        ((ChoicepositionHolder)holder).choicephone.setText(list.get(position).getChoicepositionPhone());
        ((ChoicepositionHolder)holder).choiceposition.setText(list.get(position).getChoicepositionPosition());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClickExperint(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ChoicepositionHolder extends RecyclerView.ViewHolder{
        TextView choicename, choicephone, choiceposition;

        public ChoicepositionHolder(@NonNull  View itemView) {
            super(itemView);
            choicename=itemView.findViewById(R.id.choiceposition_item_name);
            choicephone=itemView.findViewById(R.id.choiceposition_item_phone);
            choiceposition=itemView.findViewById(R.id.choiceposition_item_position);
        }
    }
    public interface OnClickExperintListener{
        void onClickExperint(int position);
    }
}
